home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / GETIMAGE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.6 KB  |  64 lines

  1.  
  2.                                         /* File       : getimage.c */
  3.                                         /* Entered by : A. Wayner */
  4. # include <graphics.h>
  5. # include <stdlib.h>
  6. # include <alloc.h>
  7.  
  8. main()
  9. {
  10.     int graphdriver = DETECT, graphmode;
  11.     char far *image;
  12.     char      buffer[80];
  13.     unsigned numbytes;
  14.  
  15.                                             /* Detect adapter type and initialize */
  16.                                             /* graphics system */
  17.     initgraph( &graphdriver, &graphmode, "\\turboc" );
  18.  
  19.                                               /* Draw some graphical objects to save */
  20.     setfillstyle( SOLID_FILL, LIGHTCYAN );
  21.     bar( 50, 50, 90, 90 );
  22.     setcolor( LIGHTMAGENTA );
  23.     ellipse( 80, 80, 0, 360, 40, 40 );
  24.  
  25.                                             /* Determine storage needed for image */
  26.     numbytes = (unsigned int ) imagesize( 0,0,50,50 );
  27.  
  28.     sprintf( buffer,
  29.     "To save 51 x 51 image using getimage, we need %u bytes of memory.",
  30.      numbytes );
  31.  
  32.     outtextxy( 10, 10, buffer );
  33.  
  34.                                             /* Allocate buffer for image */
  35.     if( (image = (char far *) malloc (numbytes) ) == (char far * ) NULL )
  36.     {
  37.         closegraph();
  38.         printf("Not enough memory for image storage \n");
  39.         exit( 0 );
  40.     }
  41.  
  42.     getimage( 50, 50, 100, 100, image ); /* save the image */
  43.     outtextxy( 10, getmaxy()-50,"Image saved. Hit any key to continue");
  44.     getch();
  45.  
  46.                                             /* Now clear screen and draw saved */
  47.                                             /* image at several screen locations */
  48.     cleardevice();
  49.     setbkcolor( CYAN );                /* Change the background color */
  50.     outtextxy( 10, 10,"Demonstrating getimage and putimage");
  51.  
  52.     putimage(80, 80, image, OR_PUT);
  53.     putimage(150, 20, image, COPY_PUT);
  54.     putimage(300,200,image, NOT_PUT );
  55.  
  56.  
  57.     outtextxy( 10, getmaxy() - 30, "Press any key to exit");
  58.  
  59.     getch();
  60.     closegraph();
  61. }
  62.  
  63.  
  64.